<?php

use app\http\middleware\AllowOriginMiddleware;
use think\facade\Config;
use think\facade\Route;
use think\Response;

/**
 * 无需授权的接口
 */
Route::group(function () {
    //用户名密码登录
    Route::post('login', 'v1.admin.AdminController/login')->name('AdminLogin')->option(['real_name' => '登录']);
    //后台登录页面数据
    Route::get('login/info', 'v1.admin.AdminController/info')->option(['real_name' => '登录信息']);
    //获取验证码
    Route::get('ajcaptcha', 'v1.admin.AdminController/ajcaptcha')->name('ajcaptcha')->option(['real_name' => '获取验证码']);
    //一次验证
    Route::post('ajcheck', 'v1.admin.AdminController/ajcheck')->name('ajcheck')->option(['real_name' => '一次验证']);

})->middleware(AllowOriginMiddleware::class)->option(['mark' => 'login', 'mark_name' => '登录相关']);

/**
 * miss 路由
 */
Route::miss(function () {
    if (app()->request->isOptions()) {
        $header = Config::get('cookie.header');
        $header['Access-Control-Allow-Origin'] = app()->request->header('origin');
        return Response::create('ok')->code(200)->header($header);
    } else
        return Response::create()->code(404);
});
